/*
 *  Copyright 2003 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 */

/*
 *  ======== evmdm642_uart.h ========
 *
 *  UART interface on the DM642 EVM
 */
#ifndef EVMDM642_UART_
#define EVMDM642_UART_

#ifdef __cplusplus
extern "C" {
#endif

#include <csl.h>

#define EVMDM642_UART_CONFIGREGS      4
#define EVMDM642_UART_BASEADDR        0x9c00
#define EVMDM642_UART_RBR             0x00  // Read
#define EVMDM642_UART_THR             0x00  // Write
#define EVMDM642_UART_IER             0x01
#define EVMDM642_UART_IIR             0x02  // Read
#define EVMDM642_UART_FCR             0x02  // Write
#define EVMDM642_UART_LCR             0x03
#define EVMDM642_UART_MCR             0x04
#define EVMDM642_UART_LSR             0x05
#define EVMDM642_UART_SCR             0x07

#define EVMDM642_UART_DLL             0x08
#define EVMDM642_UART_DLH             0x09
#define EVMDM642_UART_EFR             0x0A
#define EVMDM642_UART_XON1            0x0C
#define EVMDM642_UART_XON2            0x0D
#define EVMDM642_UART_XOFF1           0x0E
#define EVMDM642_UART_XOFF2           0x0F

#define EVMDM642_UART_TCR             0x16
#define EVMDM642_UART_TLR             0x17

#define EVMDM642_UART_FIFORDY         0x1f

#define EVMDM642_UARTA                0
#define EVMDM642_UARTB                1

#define EVMDM642_UART_BAUD115200     0x010
#define EVMDM642_UART_BAUD57600      0x020
#define EVMDM642_UART_BAUD38400      0x030
#define EVMDM642_UART_BAUD19200      0x060
#define EVMDM642_UART_BAUD9600       0x0c0
#define EVMDM642_UART_BAUD4800       0x180
#define EVMDM642_UART_BAUD2400       0x300
#define EVMDM642_UART_BAUD1200       0x600

/* UART handle */
typedef Int16 EVMDM642_UART_Handle;

/* Config structure for the EVMDM642 UART */
typedef struct EVMDM642_UART_Config {
    int regs[EVMDM642_UART_CONFIGREGS];
} EVMDM642_UART_Config;

/* Set a UART register */
extern void EVMDM642_UART_rset(EVMDM642_UART_Handle hUart, Int16 regnum, Int16 regval);

/* Get the value of a UART register */
extern Int16 EVMDM642_UART_rget(EVMDM642_UART_Handle hUart, Int16 regnum);

/* Initialize UART and return handle */
extern Int16 EVMDM642_UART_open(Int16 devid, Int16 baudrate, EVMDM642_UART_Config *Config);

/* Get one character of data from the UART */
extern Int16 EVMDM642_UART_getChar(EVMDM642_UART_Handle hUart);

/* Send one character of data to the UART */
extern void EVMDM642_UART_putChar(EVMDM642_UART_Handle hUart, Uint16 data);

#ifdef __cplusplus
}
#endif

#endif

